package app

import (
	"errors"

	"github.com/nacos-group/nacos-sdk-go/common/constant"
)

var TestConfig = Config{
	NamespaceId: "4bf2ebab-1736-42bb-8e47-0eec2bad64c2",
	AccessKey:   "7d56dcd43f5c4ecba1b9c446aed4c87d",
	SecretKey:   "u1NswKvEANMUGzBWSpoEVmveg4s=",
}

var BuildConfig = Config{
	NamespaceId: "37557c71-6cfa-4aa2-bcc2-840d8627de70",
	AccessKey:   "0d33d0cce65b4ea092a9d6f82ba7e2c2",
	SecretKey:   "iMEhvI1pLXvN3Cp4fbWnPFKYCL0=",
}

type Config struct {
	NamespaceId string //可选,本地4bf2ebab-1736-42bb-8e47-0eec2bad64c2,正式37557c71-6cfa-4aa2-bcc2-840d8627de70
	Endpoint    string //可选,本地acm.aliyun.com,正式addr-hz-internal.edas.aliyun.com
	AccessKey   string //the AccessKey for kms
	SecretKey   string //the SecretKey for kms
	Group       string //必填分组,对应不同的项目
}

func (c Config) SetGroup(g string) Config {
	c.Group = g
	return c
}

func (c Config) toNacos() (constant.ClientConfig, error) {
	conf := constant.ClientConfig{
		NamespaceId: c.NamespaceId,
		Endpoint:    c.Endpoint,
		AccessKey:   c.AccessKey,
		SecretKey:   c.SecretKey,
	}

	if len(c.Group) == 0 {
		return conf, errors.New("无效分组")
	}

	return conf, nil
}
